var core = (function ($) {
    var getRootPath = function() {
        var curWwwPath=window.document.location.href;
        var pathName=window.document.location.pathname;
        var pos=curWwwPath.indexOf(pathName);
        var localhostPaht=curWwwPath.substring(0,pos);
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
        return(localhostPaht+projectName);
    };

    /**
     *  分页组件
     */
    var getPage = function (url, config, content) {
        $.ajax({
            url:url,
            type:'post',
            dataType:'json',
            data:config,
            success:function(res)
            {
                laypage({
                    cont: 'page1',
                    pages: Math.ceil(res.data.total / config.pageSize),
                    curr: config.pageNum || 1,
                    group: 5,
                    skip: true,
                    jump: function (obj, first) {
                        if (!first) {
                            config.pageNum = obj.curr;
                            getPage(url,config,content);
                        }
                    }
                });
                $('#tbody').html(content(res,config.pageNum));
            }
        });
    };

	//返回content数据到页面，currPage便于删除数据时好定位到该类，此处未用
	function parseUserList(res,currPage){
		var content = "";
		$.each(res.data.list, function (i, o) {
			content += "<tr>";
			content += "<td>"+o.id+"</td>";
			content += "<td>"+o.openId+"</td>";
			content += "<td>"+o.applyName+"</td>";
			content += "<td>"+o.applyTelephone+"</td>";
			content += "<td>"+o.payAmount+"</td>";
            content += "<td>"+o.donationAmount+"</td>";
            content += "<td>"+o.totalAmount+"</td>";
            content += "<td>"+o.cardSegment+"</td>";
            content += "<td>"+o.description+"</td>";
            if(o.isPay == '0'){
            	content += "<td>未付款</td>";
            }else if(o.isPay =='1'){
            	content += "<td>已付款</td>";
            }
            if(o.orderStatus == '0'){
            	content += "<td>已提交</td>";
            }else if(o.orderStatus =='1'){
            	content += "<td>已付款</td>";
			}else if(o.orderStatus =='2'){
				content += "<td>审核中</td>";
			}else if(o.orderStatus =='3'){
				content += "<td>审核通过</td>";
			}
            content += "<td>"+o.orderTime+"</td>";
            content += '<td><a class="updateBtn" href="javascript:void(0)" onclick="updateOrder('+o.id+')">修改</a></td>';
			content += "</tr>";
		});
		return content;
	}
	
	//从后台获取json数据
	var getUserListByPage = function(curr,data,url){
        
		data = '{"pageNum":"'+(curr || 1)+'","pageSize":"10",'+data+'}';
		//字符串转 json 对象
		var obj = eval("("+data+")");
		core.getPage(url,obj,parseUserList);
	};
	
    return {
        getRootPath: getRootPath,
        getPage: getPage,
        getUserListByPage:getUserListByPage
    };


})(jQuery);